<?
include_once('clogin.inc.php');
include_once('admin_head.php');
/*include_once('../fckeditor/fckeditor.php');		//引用FCKeditor.php这个文件
$oFCKeditor=new FCKeditor('content');             //创建FCKeditor对象的实例
$oFCKeditor->BasePath='FCKeditor/';               //FCKeditor所在的位置，这里它的位置就是'FCKeditor/';
$oFCkeditor->ToolbarSet='Default';                //工具按钮设置
$oFCKeditor->Width='100%';                        //设置它的宽度
$oFCKeditor->Height='300px';                      //设置它的高度
$oFCkeditor->Create;
*/
?>

<? 
$model_name ='日志';
if ($_POST['action'] == 'edit'){
	$id = intval($_POST['id']);
	$weather = $_POST['weather'];
	$mood = $_POST['mood'];
	$content = $_POST['content'];
	$cid = $_POST['cid'];
	$info = 1;
	$update_time = time();
	$uid = $_SESSION["uid"];
/*	echo $id;
	echo $sitename;
	echo $url;
	echo $info;
	echo $displayid;*/

	if (empty($id)) {
		$sql = "INSERT INTO {$tablepre}blog (cid, weather, mood, content, create_time,update_time,uid) 
				VALUES('$cid', '$weather', '$mood', '$content', $update_time,$update_time,'$uid')";
		$edit = '添加';		
	}else{
		$sql = "UPDATE {$tablepre}blog SET cid = '$cid', weather = '$weather', mood = '$mood', content = '$content', uid = '$uid', update_time = '$update_time' WHERE id = $id LIMIT 1";
	
		$edit = '修改';	
	} 
	mysql_query($sql); 	
	
	if ( mysql_affected_rows() == 1 ) {
		if(mysql_insert_id()) $id = mysql_insert_id();
		 showmsg("{$model_name}{$edit}成功！",'成功',"?id=$id",'返回');
		
	}else{
		 showmsg("{$model_name}{$edit}失败或没有修改！",'失败',"return",'返回');
	}
	
}
if ($_GET['id']) {
	$id = intval($_GET['id']);
	if ($_GET['action'] == 'del'){
		$edit = '删除';	
		$sql = "DELETE FROM {$tablepre}blog WHERE id = $id LIMIT 1";
		mysql_query($sql);
		showmsg("{$model_name}{$edit}成功！",'成功',"../frmView_right.php",'返回');
		exit();
		
	}
	
	
	//$sql = "SELECT * FROM {$tablepre}note WHERE id = $id ";
	$sql = "SELECT n.*, c.pid, c.name, c.component  FROM {$tablepre}blog n LEFT JOIN {$tablepre}channel c on (n.cid = c.id) WHERE n.id= $id";
	$result=mysql_query($sql); 
	$enotes = mysql_fetch_array($result);
	

	$title .= strip_tags($enotes['content']);
	$title = preg_replace('/[\s]+/is','',$title );
	$title = mb_strcut($title,0,18,'gb2312');
	
	
	$enotes['title'] =$title ;
}

$sql = "SELECT * FROM  {$tablepre}channel WHERE component ='note'"; //分类
$result=mysql_query($sql); 
while($query = mysql_fetch_array($result)) {
$channels[]=$query;
}

?> 
<div class="edit">
<div class="title"><?php 
if ($_GET['id']) {
	echo "编辑： $enotes[title]  信息 [<a href=\"admin_blog.php\">添加一个新的</a>] [<a href=\"admin_blog.php?action=del&id=$enotes[id]\"  onclick=\"return confirm('Are you sure you want to delete?')\">删除</a>] ";
}else{
	echo "添加日志";
}
?></div>
<form id="form1" name="form1" method="post" action="">

<input name="action" type="hidden" value="edit">
<input name="id" type="hidden" value="<? echo $enotes['id'] ?>">

	<br>
    <label>标题：</label>
    <input name="title" type="text" id="title" value="<? echo $enotes['title'] ?>" size="70" readonly>

             
        <!--<select name="cid">
		<option value='0'>--请选择分类--</option>
		<?php foreach($channels as $c){?>
        <option value="<?php echo $c['id'] ?>" <?php if ( $c['id'] == $enotes['cid'] ) { echo 'selected';}?>><? echo $c['name'] ?></option>
		  <?php }?>
        </select>-->
        <br>


		

    <input name="content1"  id="content1" type="hidden" value="<?php echo htmlentities($enotes['content'], ENT_COMPAT ,'gb2312') ?>">


    <!--<INPUT id=content style="DISPLAY: none" type=hidden name="guan">
	<INPUT id=content___Config style="DISPLAY: none" type=hidden>
	<IFRAME id=content___Frame src="../FCKeditor/editor/fckeditor.html?InstanceName=guan&amp;Toolbar=Default" frameBorder=0 width=100% scrolling=no height=300>
	</IFRAME>-->

    <script type="text/javascript">
<!--
// Automatically calculates the editor base path based on the _samples directory.
// This is usefull only for these samples. A real application should use something like this:
// oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
//var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ;

var oFCKeditor = new FCKeditor( 'content' ) ;
//oFCKeditor.BasePath	= sBasePath ;
oFCKeditor.Height	= 400 ;
oFCKeditor.toolbarSet = 'myset';
oFCKeditor.Value = document.getElementById('content1').value;
oFCKeditor.Create() ;
//-->
		  </script>
	<p>
         
          <input type="submit" name="Submit" value="保存修改">
        
          <input type="button" name="Submit2" value="取消返回" onClick="history.back()">
	</p>
</form></div>

</body>
</html>